package com.book.controller;


import com.book.po.Reader;
import com.book.service.readerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;

@Controller
@RequestMapping("/reader")
public class readerController {
    @Autowired
    private readerService readerService;

    @RequestMapping("/reader_select")
    public String reader_select(RedirectAttributes  model, Reader reader){
        List<Reader> readers = readerService.reader_select(reader);
        if (readers.size()>=1){
            model.addFlashAttribute("readers",readers);
            model.addFlashAttribute("msg","");
            return "redirect:/manage/readerManage";
        }else {
            model.addFlashAttribute("msg","没有查找到对应读者！");
            return "redirect:/manage/readerManage";
        }
    }


    @RequestMapping("/reader_insert")
    public String reader_insert(RedirectAttributes  model, Reader reader){
        String msg = readerService.reader_insert(reader);
        model.addFlashAttribute("msg",msg);
        return "redirect:/manage/readerManage";
    }

    @RequestMapping("/reader_update")
    public String reader_update(RedirectAttributes  model, Reader reader){
        String msg = readerService.reader_update(reader);
        model.addFlashAttribute("msg",msg);
        return "redirect:/manage/readerManage";
    }

    @RequestMapping("/reader_delete")
    public String reader_delete(RedirectAttributes  model, Integer readerId){
        String msg = readerService.reader_delete(readerId);
        model.addFlashAttribute("msg",msg);
        return "redirect:/manage/readerManage";
    }
}
